import 'package:flutter/material.dart';
import 'package:flutter_data_json_app/data.dart';
import 'package:flutter_data_json_app/entity/deliver_list.dart';
import 'package:flutter_data_json_app/entity/request_bean.dart';
import 'package:flutter_data_json_app/http/request.dart';
import 'package:flutter_data_json_app/view/base_view.dart';


class TestPage extends StatefulWidget {
  @override
  _TestPageState createState() => _TestPageState();

  RequestBean requestBean;

  void _start(){
    Map cond=
      {"latitude":"30.29398128","longitude":"120.00024911"}
    ;
      apiGetDeliverListByDriverLoc(1, 10, cond).then((onValue){
        print(onValue.data);
        requestBean=onValue;
      });
  }


//  BaseBean con(String json,BaseBean t){
//
//    return BaseBean.fromJson(json);
//  }
//
//  T con2<T extends BaseBean>(String json){
//    return ;
//  }

//  T con3<T extends BaseBean>(String json,BaseBean baseBean){
//    return baseBean.fromJson(json);
//  }
//
//  RequestBean<T> con4<T extends BaseBean>(String json,T t){
//    return RequestBean<T>.success(code:1,msg:'咖喱给给',data:t.fromJson(json));
//  }
//
//  RequestBean con6(String json,BaseBean t){
//    return RequestBean.success(code:1,msg:'咖喱给给',data:t.fromJson(json));
//  }
//
//  Future<RequestBean<T>> con7<T extends BaseBean>(String json,T t){
//    return Future.value(RequestBean(code:1,msg:'咖喱给给',data:t.fromJson(json)));
//  }
//
//
//  BaseBean2 con5(String json){
//    return BaseBean2.fromJson(json);
//  }

}

class _TestPageState extends State<TestPage> {


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('galigeigei'),
      ),
      body:getBaseView(_getContainer2,widget.requestBean,_tryAgain)
    );
  }

  @override
  void initState() {
    super.initState();
    StaticValue.context=context;
  }

  void _start(){
    Map cond=
    {"latitude":"30.29398128","longitude":"120.00024911"}
    ;
    apiGetDeliverListByDriverLoc(1, 10, cond).then((onValue){
      print(onValue.data);
      setState(() {
        widget.requestBean=onValue;
      });
//      requestBean=onValue;
    });
  }

  void _tryAgain(){
    _start();
  }

  Widget _getContainer2(){
    return Container(
      child: Column(
        children: <Widget>[
          RaisedButton(
            onPressed: (){
              widget._start();
            },
            child: Text('开始'),
          ),
          Text(widget.requestBean.data.toString())
        ],
      ),
    );
  }
}
